<?php
    header("Content-Type:text/html;charset=utf-8");
    $conn;
    include'../public/conn.php';
    //启动session
    session_start();
    //文章编号
    $log_id = $_POST['log_id'];
    //评论人姓名
    $userName = $_SESSION['userName'];
    echo "$userName";

    $userType = $_SESSION['userType'];
    echo "$userType";
    



    //作者id
    $sql = mysql_query("SELECT *FROM log WHERE log_id = $log_id");
    $row = mysql_fetch_array($sql);
    $sID = $row['sid'];
    //评论人ID
    if($userType = "0"){
    $id = $_SESSION['tid'];

    }
    else $id = $_SESSION['sid'];
    //评论内容
     //post接收数据,只是演示效果,这里就省去验证了
    $content = $_REQUEST['reply_content'];

 

     //判断评论是否为空
    if($content==""){

    	echo("<script>");
		echo("alert('请输入评论！');");
		echo("window.location='log_read.php?id=$log_id';");
		echo("</script>");
		die();
    }

     // 对特殊字符处理
  	$content = addslashes($content);

    //插入数据
    if($userType = "0"){
             
		$query = "INSERT INTO `reply` ( `log_id` , `tid` , `reply_content` , `reply_date` , `reply_time` )
                 VALUES ('$log_id', '$id', '$content', NOW(), NOW())";
	}
	else {
       $query = "INSERT INTO `reply` ( `log_id` , `sid` , `reply_content` , `reply_date` , `reply_time` )
                 VALUES ('$log_id', '$id', '$content', NOW(), NOW())";
        /*$query =  "INSERT INTO `reply` ( `log_id` , `sid` , `reply_content` , `reply_date` , `reply_time` )
                    VALUES ('$log_id', '$id', '$reply_content', 'NOW()', 'NOW()')";*/
		/*$query = "INSERT INTO reply (log_id, sid, reply_content, reply_date, reply_time) 
				  VALUES ($log_id, $id, '$reply_content', NOW(), NOW())";*/
		$result = mysql_query($query, $conn);
	}
	
    echo $result;
	//判断是否发表成功
if($result)
	{
		
		echo("<script>");
		echo("alert('发表成功');");
		echo("window.location='log_read.php?id=$log_id';");
		echo("</script>");
		
		}
    else{
    	echo("<script>");
		echo("alert('发表失败');");
		echo("window.location='log_read.php?id=$log_id';");
		echo("</script>");
    }

?>